package com.learn.mq.config;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:RocketMQConfig
 * Package:com.learn.mq.config
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/30 - 18:10
 * @Version:v1.0
 */
@Configuration
public class RocketMQConfig {
    @Value("${rocketmq.name-server}")
    private String nameServer;

    @Bean
    public RocketMQTemplate defaultRocketMQTemplate(){
        RocketMQTemplate template = new RocketMQTemplate();
        DefaultMQProducer mqProducer = new DefaultMQProducer("GXS-LEARN-MQ");
        mqProducer.setNamesrvAddr(nameServer);
        template.setProducer(mqProducer);
        return template;
    }

    @Bean
    public RocketMQTemplate transactionRocketMQTemplate(){
        RocketMQTemplate template = new RocketMQTemplate();
        TransactionMQProducer mqProducer = new TransactionMQProducer("GXS-LEARN-MQ");
        mqProducer.setNamesrvAddr(nameServer);
        template.setProducer(mqProducer);
        return template;
    }
}
